<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>题库增改</title>
    <style type="text/css">

    .bo,html{
            margin:0%;
            padding:0%;
            height:100%;
            background: mintcream;
        }
        .left{
            float:left;
            width:50%;
            height:100%;
            background: aqua;
        }
        .right
        {
            float:right;
            width:50%;
            height:100%;
            background: #fffbfb;
        }
        .ta {
            height:400px; width:300px; margin-top:15px;resize:none;

        }
    </style>
</head>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
    function getCookie(c_name)//获取cookie内容
    {
        if (document.cookie.length>0)
        {
            c_start=document.cookie.indexOf(c_name + "=")
            if (c_start!=-1)
            {
                c_start=c_start + c_name.length+1
                c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            }
        }
        return ""
    }
    var username=getCookie('username');
    if(username=='')
    {
        setTimeout('location.href="login.html";',0);
    }
    function zengjia()
    {
        var str1=document.getElementById("select").value;
        var formData = new FormData();
        formData.append('file', $("#exl")[0].files[0]);
        var url;
                 if(str1=="单选")
                {
                    url= "/single/upload";
                }
                else if(str1=="多选") {
                   url="/multi/upload";
                }
                else
                {
                    url="/tfng/upload";
                }
        $.ajax({
            type: "post",
            url: url,
            data: formData,
            async: true,
            dataType: "json",
            processData: false,
            contentType:false,
            success: function (data)
            {
                   /*if(data==0)
                   {
                       alert("格式或题目类型错误");
                       $("#str").val("");
                   }
                   else {*/
                       alert("增加成功！");
                       $("#str").val("");
                   //}

            },
            error:function (data) {
                alert("格式或题目类型错误");
                $("#str").val("");
            }
        });
    }
</script>
<body class="bo">
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<div class="container-fluid col bo">

    <div style="background: teal" class="row">
        <div class="text-left">
            <h1><i class=" fa fa-plus-square-o "></i>题库增改</h1>
        </div>
        <div class="text-right" >
            <i class="fa fa-user-circle" style="font-size:40px"></i>
        </div>
    </div>

    <div  class="row bo">

        <div style="background: aliceblue" class="left">
            <div style="margin-left:20px">
                <div>
                    <h2>使用说明</h2>
                    <p style="font-size:1.2em">
                        1.题目增加分三种类型，单选判断，多选，请先选择题目类型</br>
                        2.题目增加采用提交excel表格的形式，格式如下：
                    </p>
                </div>
                <h3>单选题：</h3>
                <img src="/static/images/single.png" style="width:90%;height:auto;margin:auto 5%">
                <h3>多选题：</h3>
                <img src="/static/images/multi.png" style="width:90%;height:auto;margin:auto 5%">
                <h3>判断题：</h3>
                <img src="/static/images/tf.png" style="width:90%;height:auto;margin:auto 5%">
            </div>
        </div>

        <div class="right col">
            <form id="myform">
                <div style="margin-top:10%;margin-bottom:15%;margin-left:15%;">
                    请选择所加题目类型:<select id="select"  placeholder="所添加题目类型">
                    <option vlaue="单选">单选</option>
                    <option vlaue="多选">多选</option>
                    <option vlaue="判断">判断</option>
                </select>
                </div>
                <div style="margin-left:15%">
	                          <span>

		                      <label style="float:left">上传文件：</label>

		                      <input  type="file" id="exl" size="27"  style="float:left;background-color: gainsboro" name="upload"/>

	                          </span>
                    <div style="clear:both"></div>

                </div>


                    <div class="row" style="margin-top:20%; margin-left:15%;">
                        <span><a href="enter.html"><div class="col-md-6" style="float: left"><button type="button" class="btn btn-danger"><i class="fa fa-reply"></i>退出</button></div></a></span>
                        <div class="col-md-6" style="float: right"><button type="button" class="btn btn-primary" onclick="zengjia()"><i class="fa fa-paper-plane"></i>提交</button></div>
                    </div>

                <!--注意此处 button的类型不能为submit，只能为button否则可能引起ajax虽然可以向后台请求数据却会进入error中-->

            </form>
        </div>

    </div>

</div>
</body>
</html>




